﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.Support;

namespace DomainModel.PDC
{
    public class Customer
    {
        public int CustomerId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
        public string PostalCode { get; set; }
        public string City { get; set; }

        private List<Vehicle> _vehicles;

        public IEnumerable<Vehicle> Vehicles { get { return _vehicles; } }

        public Customer()
        {
            _vehicles = new List<Vehicle>();
        }

        public void OwnsFollowingVehcile(Vehicle vehicle)
        {
            if (vehicle == null) throw new ArgumentNullException("vehicle");
            if (!_vehicles.Contains(vehicle))
            {
                vehicle.Owner = this;
                _vehicles.Add(vehicle);
            }
        }

        public List<BrokenBusinessRule> GetBrokenRules()
        {
            List<BrokenBusinessRule> brokenRules = new List<BrokenBusinessRule>();


            if (String.IsNullOrEmpty(FirstName))
                brokenRules.Add(new BrokenBusinessRule("FirstName", "A customer must have a first name"));

            if (String.IsNullOrEmpty(LastName))
                brokenRules.Add(new BrokenBusinessRule("LastName", "A customer must have a last name"));


            //if (Address == null)
            //    brokenRules.Add(new BrokenBusinessRule("Address", "A customer must have an address."));

            return brokenRules;
        }

        private void AddToBrokenRulesList(List<BrokenBusinessRule> currentBrokenRules, List<BrokenBusinessRule> brokenRulesToAdd)
        {
            foreach (BrokenBusinessRule brokenRule in brokenRulesToAdd)
            {
                currentBrokenRules.Add(brokenRule);
            }
        }



        public bool CanBeDeleted
        {
            //TODO check for unpaid bill
            get { return true; }
        }
    }
}
